﻿namespace Viz
{
    using System;
    using System.Windows.Media;
    using Microsoft.Xna.Framework.Graphics;

    public class Triangles: Processing
    {
        protected float                                 LIGHT = 1f;
        protected VertexPositionColor[]                 b1;    
        protected VertexPositionColor[]                 b2;

        public override void setup()
        {
        }

        public override void draw()
        {
            background(Colors.Black);
            view();
            light(LIGHT);

            fill(1f, 0f, 0f);
            push();
            rotateZ((MILLISECONDS / 700) % (Math.PI * 2));
            rotateY((MILLISECONDS / 700) % (Math.PI * 2));
            rotateX((MILLISECONDS / 700) % (Math.PI * 2));
            box(Colors.Yellow);

            //draw(-1, -1, 1,
            //      0,  1, 0,
            //      1, -1, 0);
            //pop();

            //fill(0f, 0f, 1f);
            //push();
            //rotateX((MILLISECONDS / 600) % (Math.PI * 2));
            //translate(0.2f, 0.2f, 0.2f);
            //draw( 1, -1, 1,
            //      0,  1, 0,
            //     -1, -1, 0);
            //pop();

            //push();
            //    fill(0f, 1f, 0f);
            //    translate(1f, 1f, 0.1f);
            //    rotateY((MILLISECONDS / 500) % (Math.PI * 2));
            //    text("Hello world: " + DateTime.Now.ToLongTimeString(), Colors.Yellow, Color.FromArgb(255, 0, 0, 0), 64, "Arial");
            //pop();

            //DrawCos();

            invalidate();
        }

        private static VertexPositionColor[] b; 
        public void DrawCos()
        {
            push();
            translate(-15f, 0f, 0f);
            rotateZ((MILLISECONDS / 500) % (Math.PI * 2));
            rotateY((MILLISECONDS / 500) % (Math.PI * 2));
            rotateX((MILLISECONDS / 500) % (Math.PI * 2));
            if (b == null)
            {
                Func<float, float, float> func = (x, y) => (float)(Math.Cos((x + x / 2) * Math.PI / 4) + Math.Cos((y) * Math.PI / 4));
                b = plot(-10f, 10f, -10f, 10f, 150, func);
            }
            else
            {
                plot(b);
            }
            pop();
        }

        public void LightUp()
        {
            LIGHT = Math.Min(1f, LIGHT + 0.01f);
        }

        public void LightDown()
        {
            LIGHT = Math.Max(0f, LIGHT - 0.01f);
        }

        public void Far()
        {
            Z -= 0.3;
        }

        public void Near()
        {
            Z += 0.3;
        }

        public void Left()
        {
            X -= 0.05;
        }

        public void Right()
        {
            X += 0.05;
        }

        public void Up()
        {
            Y -= 0.05;
        }

        public void Down()
        {
            Y += 0.05;
        }
    }
}
